﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BaseSet.Data;
using BaseSet.Logic;
using BaseSet.Entity;
using BaseSet.Framework;
using BaseSet.Entity.Common;
using BaseSet.Entity.Common.Text;
using BaseSet;
using System.Data;

namespace WebSite.Admin.BlogManager
{
    public partial class BlogTypeManager : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                LoadContent(false);

                // 从BasePage中得到
                PageLiteral.Text = BuildPageLinks();
            }
        }


        #region 加载列表
        private void LoadContent(bool mark)
        {

            //设置控件属性，从BasePage中得到
            PageConfig(BlogTypeUPager);


            //List<Member> list = new List<Member();
            BlogTypeHelper bthelper = new BlogTypeHelper();

            Criteria c = new Criteria();
            c.Add(CriteriaType.Equals, "Flag", 0);

            BlogTypeUPager.ItemCount = bthelper.QueryBlogTypeCountBySearch(c);

            // 以下的值从BasePage中得到
            BlogTypeUPager.UrlFormat = UrlFormat;
            BlogTypeUPager.PrefixText = GetPreFixText(BlogTypeUPager);

            if (mark)
            {
                PagerInit(BlogTypeUPager);
            }

            string[] fields = new string[] { "ID", "BlogBigType", "BlogTypeName", "Flag", "CreateDate" };

            DataTable dt = new DataTable();

            dt = bthelper.QueryBlogTypeBySearchToTable(c, new Order[] { new Order("CreateDate", OrderMode.Desc) }, BlogTypeUPager.Begin - 1, BlogTypeUPager.Count, fields);


            rptBlogType.DataSource = dt;
            rptBlogType.DataBind();
        }
        #endregion

        #region 列表事件
        protected void rptBlogType_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            HiddenField hidID = (HiddenField)e.Item.FindControl("hidID");
            TextBox tbBlogTypeName = (TextBox)e.Item.FindControl("txtBlogTypeName");

            string id = hidID.Value;


            if (e.CommandName == "edit")//编辑
            {
                string blogtypename = tbBlogTypeName.Text.Trim();
                if (string.IsNullOrEmpty(blogtypename))
                {
                    Tools.Alert("请输入类别名称！");
                    return;
                }
                BlogTypeHelper bthelper = new BlogTypeHelper();
                BlogType btinfo = new BlogType();

                btinfo = bthelper.GetBlogType(id);

                btinfo.ID = id;
                btinfo.BlogTypeName = blogtypename;

                bthelper.EditBlogType(btinfo);

                Tools.Alert("修改成功！");
            }

            LoadContent(false);
        }
        #endregion

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            Response.Redirect("BlogTypeAdd.aspx");
        }
    }
}